package com.learn.springcloud.hystrixexplainindetailconsumer.request.collapser.controller;

import com.learn.springcloud.hystrixexplainindetailconsumer.bean.User;
import com.learn.springcloud.hystrixexplainindetailconsumer.request.collapser.service.RequestCollapserAnnotationService;
import com.learn.springcloud.hystrixexplainindetailconsumer.request.collapser.service.RequestCollapserExtendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 请求合并消费者
 * @Time : 2018/8/6 16:47
 * @Version : 1.0
 */
@RestController
public class RequestCollapserConsumer {

    @Autowired
    private RequestCollapserExtendService requestCollapserExtendService;

    @Autowired
    private RequestCollapserAnnotationService requestCollapserAnnotationService;

    @RequestMapping("/request/collapser/find/user/extend/way/{id}")
    public User findUser1(@PathVariable Long id){
        return requestCollapserExtendService.find(id);
    }

    @RequestMapping("/request/collapser/find/users/extend/way")
    public List<User> findUsers1(@RequestBody List<User> users){
        System.out.println(users);
        List<Long> ids = users.stream().map(User::getId).collect(Collectors.toList());
        return requestCollapserExtendService.finds(ids);
    }

    @RequestMapping("/request/collapser/find/user/annotation/way/{id}")
    public User findUser2(@PathVariable Long id){
        return requestCollapserAnnotationService.find(id);
    }

    @RequestMapping("/request/collapser/find/users/annotation/way")
    public List<User> findUsers2(@RequestBody List<User> users){
        System.out.println(users);
        List<Long> ids = users.stream().map(User::getId).collect(Collectors.toList());
        return requestCollapserAnnotationService.finds(ids);
    }
}
